﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Warehouse.DataAccess
{
    public partial class PurchaseView : CustomView<PurchaseView>
    {
        public static double GetShouldPay(int supplierID, DateTime endDate)
        {
            using (WarehouseClassesDataContext context = new WarehouseClassesDataContext())
            {
                return (from t in context.PurchaseView where t.SupplierID == supplierID && t.PurchaseDate < endDate && t.Status == (int)BillStatus.Default select new { Amount = (double?)t.Amount, Type = t.Type }).Sum(p => p.Amount * (p.Type == (int)PurchaseBillType.Return ? -1 : 1)) ?? 0;
            }
        }
    }
}
